
#ifndef __SOCKET_H__
#define __SOCKET_H__

#include <winsock2.h>
#include <ws2tcpip.h>
#include <vector>
#include "TEDefs.h"
using namespace std;

// Port Used
#define SOCKET_PORT 2503

// Method defines
#define SERVER_ACCEPT (WM_USER + 1)
#define SERVER_DATA   0x0800
#define CLIENT_DATA   (WM_USER + 2)

// Global variables
extern WSADATA wsaData;

// Creation / Destruction methods
void InitSockets();
void CleanupSockets();

class TEServer
{
public:

	// Constructor
	TEServer();
	~TEServer() { closesocket(server); }

	// If all is good
	bool isValid;

	// Socket
	SOCKET server;
	struct sockaddr_in sock;
	//struct addrinfo *result;
	vector<SOCKET> clients;
};

extern TEServer *mainServer;

// Global Methods
void ServerAccept(WPARAM wParam, LPARAM lParam);
void ServerData(WPARAM wParam, LPARAM lParam, uint i);

class TEClient
{
public:

	// Constructor
	TEClient(const char *ip, uint len);
	~TEClient() { closesocket(client); }

	// If all is good
	bool isValid;

	// Socket
	SOCKET client;
	struct hostent *host;
	struct sockaddr_in localSin, remoteSin;
};

extern TEClient *mainClient;

// Gloabal Methods
void ClientData(WPARAM wParam, LPARAM lParam);

#endif // __SOCKET_H__